<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>倒计时</title>
    <style>
        div {
            width: 300px;
            height: 500px;
            background: -webkit-linear-gradient(top, rgb(240, 240, 125), pink);
            border-radius: 50%;
            margin: 10px auto;
            line-height: 500px;
            text-align: center;
            font-size: 24px;
        }
    </style>
</head>

<body>
    <div></div>
    <script>
        let time = setInterval(() => {
            let d1 = +new Date();
            let d2 = +new Date('2022-11-01 00:00:00');
            console.log(d1);
            console.log(d2);
            let differ = (d2 - d1) / 1000; // 两个时间的差值的秒数

            let second = parseInt(differ % 60);         // 获取秒
            let minute = parseInt(differ / 60 % 60);    // 获取分
            let hour = parseInt(differ / 60 / 60 % 24)  // % 24 获取天
            // console.log(hour,minute,second);
            second = second > 10 ? second : '0' + second;
            minute = minute > 10 ? minute : '0' + minute;
            hour = hour > 10 ? hour : '0' + hour;
            console.log(hour + '\t:\t' + minute + '&nbsp;:&nbsp;' + second);
            let div = document.querySelector('div');
            div.innerHTML = hour + ':' + minute + ':' + second;
        }, 1000);


    </script>
</body>

</html>